package edu.towson.cosc.cosc455.chad.markdowncompiler;

import java.util.*;
import java.io.*;

public class Compiler {
 static String token;

 
    public static Stack<String> temp = new Stack<String>();
    public static String text = "";
    
    
    public static MySyntaxAnalyzer syntax = new MySyntaxAnalyzer(); 
  
    
    public static Scanner scan;
    public static BufferedWriter write;
    
    public static void main(String[] args) throws IOException, CompilerException 
    {
     
     //read in the text file
     boolean fileFound = false;
     
     Scanner scan = new Scanner(System.in);
     System.out.println("Enter the file name: ");
     String fileName = scan.nextLine();
     boolean validFile = false;
     while(!validFile){
      if(fileName.substring(fileName.length()-4).equals(".mkd")){
       validFile = true;
      }
      else{
          System.out.println("Enter a valid file name: ");
          fileName = scan.nextLine();
      }
     }
  
     try{
            scan = new Scanner(new File(fileName));
            String line = "";
            while(scan.hasNextLine())
            {
             line = scan.nextLine();
             text = text + line;
            }
            
            fileFound = true;
            scan.close();
     }
     catch(IOException e)
     {
      fileFound = false;
      System.out.println("File was not found.");
      scan.close();
      e.printStackTrace();
     } 
     
     if(fileFound){
      token="";
  
      try{
       syntax.document();
      }
      catch(CompilerException e){
       e.printStackTrace();
      }

      write= new BufferedWriter(new FileWriter(fileName.substring(0,fileName.length()-9) + "\\test.txt"));
      write.close();
             
      
       }
     scan.close();
     System.out.println("If you see no errors, the conversion was Successful");
    }
}


